var app = getApp(),
  that,
  util = require("../../../utils/util.js");
var integralabc = ((wx.getStorageSync("bizUserInfo")).integral)
console.log(integralabc)

if (integralabc == null) {
  integralabc = 0
} else {
  integralabc = (wx.getStorageSync("bizUserInfo").integral)
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLogin: true,
    issq: !1,
    showModal: !1,
    kgvip: !1,
    isvip: !1,
    issc: !1,
    btnshowModal: !1,
    vipLevelInfo: {},
    bizUserInfointergal: '',
    conponNumber: '',
    integral: '',
    partner:'成为代理人'
  },
  onLoad: function(t) {
    console.log(t)
    that = this
    console.log(integralabc, '积分值')
    that.setData({
      vipLevelInfo: wx.getStorageSync("vipLevelInfo"),
      bizUserInfointergal: integralabc,
    })
    if (wx.getStorageSync('carPartner') !==''){
      that.setData({
      partner: wx.getStorageSync('carPartner')
      })
    }
  },
  partner: function() { //成为分销商
    console.log(111)
    that = this
    wx.request({
      url: app.api.distpartnerinfo() + `?memberId=${wx.getStorageSync("bizUserInfo").id}`,
      // url: app.api.distpartnerinfo() + `?memberId=26`,
      success: function(res) {
        console.log(res.data.data,'合伙人')
        wx.setStorageSync('yQqrCode', res.data.data)
          if (res.data.data == null) {
            wx.navigateTo({
              url: '/page/mine/pages/applyAgent/applyAgent',
            })
            that.setData({
              partner: '成为代理人'
            })
          }
        else if (res.data.code == 1) {
          if (res.data.data == null) {
            wx.navigateTo({
              url: '/page/mine/pages/applyAgent/applyAgent',
            })
            that.setData({
              partner: '成为代理人'
            })
          } else if (res.data.data.state == 1) {
            wx.setStorageSync('companyName', res.data.data.companyName)
            wx.setStorageSync('qrCode', res.data.data)
            wx.navigateTo({
              url: '/page/mine/pages/partner/partner',
            })
            that.setData({
              partner: '车管家代理人'
            })
            wx.setStorageSync('carPartner', '车管家代理人')
          } else {
            wx.navigateTo({
              url: '/page/mine/pages/applyAgent/applyAgent',
            })
          }
        }
      }
    })
  },
  reLoad: function() {;
    console.log("reLoad()");
    var a = this;
    app.getUserInfo(function(t) {
      a.setData({
        userInfo: t
      });
    });
  },
  // 获取优惠券
  getConpon: function() {
    var that = this,
      memberId = wx.getStorageSync('bizUserInfo').id;
    app.getData({
      url: app.api.getWdkq(),
      method: 'GET',
      data: {
        status: 1,
        memberId: memberId,
        companyId: app.globalData.companyId
      },
      ok: res => {
        console.log(res)
        if (res.statusCode == 200 && res.errMsg == 'request:ok') {
          if (res.data.code == 1) {
            that.setData({
              conponNumber: res.data.data.length
            })
          }
        }

        // if (res.statusCode == 200 && res.errMsg == 'request:ok') {
        //   if (res.data.code == 1) {
        //     console.log("优惠券信息", res.data.data);
        //     for (var cd = res.data.data, djq = [], zkq = [], i = 0; i < cd.length; i++) {
        //       cd[i].couponType == 1 ? djq.push(cd[i]) : zkq.push(cd[i])
        //     }
        //     console.log(djq, zkq)
        //     that.setData({
        //       djq: djq,
        //       zkq: zkq
        //     })
        //   }
        // }
      }
    })
  },
  onReady: function() {},
  bindGetUserInfo: function(t) {
    console.log(t), "getUserInfo:ok" == t.detail.errMsg && (this.setData({
      btnshowModal: !1
    }), this.changeData());
  },
  onShow: function() {
    var e = wx.getStorageSync("bizUserInfo");
    console.log(e)
    e ? this.setData({
      bizUserInfo: e
    }) : this.setData({
      bizUserInfo: this.data.bizUserInfo
    });
    // 获取会员积分
    this.setData({
      integral: wx.getStorageSync('bizUserInfo').integral
    })
    // 获取优惠券信息
    this.getConpon();
  },
  onHide: function() {},
  onUnload: function() {},
  // onPullDownRefresh: function() {
  //   this.changeData(), setTimeout(function() {
  //     wx.stopPullDownRefresh();
  //   }, 1e3);
  // },
  onReachBottom: function() {}
});